package com.wecan.saasdata.service;

import com.wecan.base.PO.Oss;
import com.wecan.saasdata.mapper.OssMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author liuzhihao
 * @Date 2022.01.15
 * @Version 1.0.0
 * @Description oss服务
 */
@Component
public class OssService {

    @Autowired
    OssMapper ossMapper;

    @Transactional
    public int increCount(String key) {
        Oss oss = ossMapper.queryOssLock(key);
        if (oss == null) {
            return 0;
        }
        oss.setCount(oss.getCount() + 1);
        return ossMapper.updateById(oss);
    }

    @Transactional
    public int decreCount(String key) {
        Oss oss = ossMapper.queryOssLock(key);
        if (oss == null) {
            return 0;
        }
        oss.setCount(oss.getCount() - 1);
        return ossMapper.updateById(oss);
    }
}
